package com.qf.dao.impl;

import com.qf.dao.UserDao;
import com.qf.pojo.User;
import com.qf.utils.DBtools;
import com.qf.utils.SQL;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

/**
 * Created by Administrator on 2021/10/21.
 */
public class UserDaoImpl implements UserDao {
    private QueryRunner queryRunner=new QueryRunner(DBtools.getDataSource());

    @Override
    public User selectOne(String name, String pass) {
        try {
            if (pass == null) {
                //根据用户昵称查询---昵称是否可用
                String sql = "select "+ SQL.USER+" from sys_user where u_name=?";
               return  queryRunner.query(sql, new BeanHandler<User>(User.class), name);
            } else {
                //根据昵称和密码查询---用户登录功能
                String sql = "select "+ SQL.USER+" from sys_user where u_name=? and u_pass=?";
                return  queryRunner.query(sql, new BeanHandler<User>(User.class), name,pass);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    //sql: select * from sys_user where name=?
}
